#include "cg_remote_control/udp_backend.hpp"
#include <iostream>
#include <string>
using namespace CG;

int main()
{
    auto p1 = NetEndPoint("127.0.0.1", 8000);
    auto p1_local = NetEndPoint(8000);
    auto p2 = NetEndPoint("127.0.0.1", 8001);
    auto p2_local = NetEndPoint(8001);
    UDPBackEnd end1(p1_local);
    UDPBackEnd end2(p2_local);

    std::string msg = "Hello, world!";
    end1.Send(reinterpret_cast<const unsigned char *>(msg.data()), msg.size(), p2);
    unsigned char buffer[1024];
    ssize_t len;
    NetEndPoint sender;
    while (!end2.Receive(buffer, 1024, len, sender))
    {
    }
    std::cout << "receive:" << std::string(reinterpret_cast<char *>(buffer), len) << std::endl;
    return 0;
}